using ExtendedMvc.Html;

namespace ExtendedMvc.Elements {
	//public class RadioButton<TModel> : RadioButtonBase<RadioButton<TModel>, TModel> where TModel : class {
	//    public RadioButton(IModelViewHelper<TModel> helper, string memberName, object value, bool isChecked) : base(helper, memberName, value, isChecked) { }
	//}

	public class RadioButtonOption<TModel> : RadioButtonBase<RadioButtonOption<TModel>, TModel> where TModel : class {
		public RadioButtonOption(IModelViewHelper<TModel> helper, string memberName, object value, bool isChecked) : base(helper, memberName, value, isChecked) { }

		//protected override void SetId() {
		//    if (id == null) Id(string.Format("{0}_{1}", id, value));
		//    base.SetId();
		//}
	}

	public abstract class RadioButtonBase<T, TModel> : Input<T, TModel>
		where T : RadioButtonBase<T, TModel>
		where TModel : class {
		private bool _checked;

		protected RadioButtonBase(IModelViewHelper<TModel> helper, string memberName, object value, bool isChecked)
			: base(helper, HtmlInputType.Radio, value, memberName) {
			Checked(isChecked);
		}

		public virtual T Checked(bool isChecked) {
			_checked = isChecked;
			return (T)this;
		}

		protected override LabelPosition defaultLabelPosition { get { return LabelPosition.After; } }

		protected override void Prepare() {
			if (_checked) SetAttribute(HtmlAttribute.Checked, HtmlAttribute.Checked);
			base.Prepare();
		}
	}
}